package com.longge;

import java.util.HashSet;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/17
 * @描述
 */
public class FindJudge {
    public int findJudge(int n, int[][] trust) {
        HashSet<Integer> set = new HashSet<>();
        for (int[] t : trust) {
            set.add(t[0]);
        }
        if (set.size() != n - 1) return -1;
        if (n == 1) return 1;
        int judge = 0, num = 0;
        for (int i = 1; i <= n; i++) {
            if (!set.contains(i)) judge = i;
        }
        for (int[] t : trust) {
            if (judge == t[1]) num++;
        }
        if (num == n - 1) return judge;
        return -1;

    }
}
